/**
 * 加载页面
 */
(function() {
	var scripts = document.getElementsByTagName("script")
	var currentScriptPath = scripts[scripts.length-1].src;
	app.directive('zLoading',['$http','$compile','$timeout',function($http,$compile,$timeout) {
		return {
			restrict:'A',
			scope: {
				isLoading:'='
			},
			link: function(scope,element,attrs,controller){
				//不读取模板是为了减少一环请求以及回调的时间，来显示loading，否则比请求数据晚一步执行
				var loadingHTML = 
					"<div style='z-index:1000000;position: absolute; width: 100%; height: 100%; display: block; background: black; opacity: 0.1; left: 0px; top: 0px;'>" + 
						"<table style='text-align: center; width: 100%; height: 100%;'>" + 
							"<tr>" + 
								"<td><img src='static/css/img/loading-spinning-bubbles.svg' width='64' height='64'></td>" + 
							"</tr>" + 
						"</table>" +
					"</div>";
				
					var loadingModal = $compile(loadingHTML)(scope);
					scope.loadingModal = loadingModal;
					loadingModal.appendTo(angular.element('body')).hide();
					scope.$watch('isLoading',function(newValue,oldValue) {
						if(newValue == oldValue) {
							return;
						}
						if(newValue&&newValue.constructor == Boolean) {
							scope.loadingModal.show();
						} else {
							$timeout(function() {
								scope.loadingModal.hide();
							}, 200);
						}
						
					});
			}
		};
	}]);
}());